package com.xz.cstone.data;

import java.util.ArrayList;
import java.util.Enumeration;

import weka.core.*;

public class ClusterData {
	
	 public ArrayList<Attribute> attributes = new ArrayList<Attribute>();
	 
	 public ArrayList<CElement> elements = new ArrayList<CElement>();
	 
	 public ClusterData()
	 {
		 
	 }
	 
	 public ClusterData(Instances instances)
	 {
		for (int i = 0; i < instances.numAttributes(); i++) {
			Attribute attribute = new Attribute();
			
			String attr_name = instances.attribute(i).name();			
			attribute.setName(attr_name);
			
			if(attr_name.equals("Wifes_education") ||
				attr_name.equals("Husbands_education") ||
				attr_name.equals("Standard-of-living_index"))
				attribute.setType(2);
			else
				attribute.setType(instances.attribute(i).type());
			
			if(attribute.getType() != 0)
			{
				Enumeration allValues = instances.attribute(i).enumerateValues();
				while(allValues.hasMoreElements())
				{
					String singleV = allValues.nextElement().toString();
					attribute.addValue(singleV);
				}
			}
			
			this.attributes.add(attribute);
		}
		

		if(instances.numInstances() == 0) elements = null;
		else{
			for (int i = 0; i < instances.numInstances(); i++) {
				CElement element = new CElement();
				element.setSize(instances.numAttributes());
				for (int j = 0; j < instances.numAttributes(); j++) {
					element.addValue(instances.instance(i).toString(j));
				}
				
				this.elements.add(element);
			}
		}
		
	 }
}
